/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bai2io;

import java.io.*;
import java.util.Scanner;

class File{
    void ReadFile(String filename) throws FileNotFoundException, IOException {
        Scanner input;
        try (FileInputStream in = new FileInputStream(filename)) {
            input = new Scanner(in);
            int i=1;
            String s = "";
            while(input.hasNextLine()) {
                String line=input.nextLine();      
                s+=line;
                System.out.println((i++)+". "+line);
            }
            System.out.println(s);
        }
        input.close();     
    }   
    
    void Write2File(String fileName,String filename1) throws IOException{
        PrintWriter output;
        try (FileOutputStream out = new FileOutputStream(fileName)) {
            output = new PrintWriter(out,true);
            FileInputStream in=new FileInputStream(filename1);
            Scanner input=new Scanner(in);                   
            while(input.hasNextLine()) {
                String line=input.nextLine();      
                output.println(line);            
            }            
        }
        output.close();
    }
    
    void Write2File(String fileName) throws IOException{
        PrintWriter output;
        try (FileOutputStream out = new FileOutputStream(fileName)) {
            output = new PrintWriter(out,true);
            output.println("Tran quang ngoc");
        }
        output.close();
    }
    
    public void getInfor(String name){   
        
        String files;
        java.io.File folder = new java.io.File(name);
        java.io.File[] listOfFiles = folder.listFiles();
        System.out.println("Các tệp trong folder "+name+" là ");
        for (int i = 0; i < listOfFiles.length; i++)       
            if (listOfFiles[i].isFile()){                
                files = listOfFiles[i].getName();
                System.out.println(files);              
            }      
    }   
}
 
public class Bai2io {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        File ngoc= new File();
        ngoc.ReadFile("example.txt");
        ngoc.Write2File("ngocquang.txt","tranquangngoc.mp3");
        ngoc.getInfor("ngoc");
    }
}
